package com.xmy.aboutThread;

// 多线程基础 构造线程的两种方式 1）继承Thread类；2）实现Runnable接口
public class Demo1 {
    public static void main(String[] args) {
        MyThread1 thread1 = new MyThread1("MyThread1");
        thread1.start();


        for (int i = 0; i < 10; i++) {
            System.out.println("Main Thread " + i);
        }
/*        System.out.println(thread1.getName());
        System.out.println(thread1.getState().toString());

        MyThread2 thread2 = new MyThread2();
        Thread thread = new Thread(thread2);
        thread.start();


        System.out.println(thread1.getState().toString());*/

    }
}

// 继承 Thread 类
class MyThread1 extends Thread {
    @Override
    public void run() {
        super.run();
        for (int i = 0; i < 10; i++) {
            System.out.println("MyThread1 "+ i);
        }
    }

    // 此构造方法提供为线程命名的方式
    public MyThread1(String name) {
        super(name);
    }

    // 获取线程当前状态
    @Override
    public State getState() {
        return super.getState();
    }
}

// 实现 Runnable 接口
class MyThread2 implements Runnable {

    @Override
    public void run() {
        System.out.println("MyThread2");
    }

}